var type = RequestURLParam.getParam("type");
var id = RequestURLParam.getParam("id");
var minForm;
var urlTxt = "sysImgconfig!add.do";
$(document).ready(function () {
    AttachUpload.init('filePicker', null, id, "attachId", "/系统图片", "uploadCallback");
    minForm = new mini.Form("form");
    if (type == "edit") {
        urlTxt = "sysImgconfig!update.do";
        init_data();
    }
});

function init_data() {
    ActHttpRequest("sysImgconfig!findById.do?id=" + id, {}, function (data) {
        if (data.OK == "OK") {
            if (data.sysImgconfig) {
                $("#form .sysImgconfig").each(function () {
                    mini.get(this.id).setValue(data.sysImgconfig[this.id]);
                });
                /*************添加非mini组件的初始化或mini中value/Text等组合组件的初始化 start*************************/
                if (data.sysImgconfig.attachId && data.sysImgconfig.attachId.trim().length > 10) {
                    $("#Image").attr('src', getfile(data.sysImgconfig.attachId,'1'));
                }

                /*************添加非mini组件的初始化或mini中value/Text等组合组件的初始化 end*************************/
            }
        } else {
            mini.alert(data.message);
        }
    }, null, null, null, '加载中。。。');
}

function saveData() {
    minForm.validate();
    if (minForm.isValid() == false) {
        mini.alert("验证失败，点击页面红色叹号查看！");
        return;
    }
    var formData = $("#form").serializeJSON();
    ActHttpRequest(urlTxt, formData, function (data) {
        if (data.OK == "OK") {
            window.CloseOwnerWindow("OK");
        } else {
            mini.alert(data.message);
        }
    }, null, null, null, '保存中。。。', true);
}

function uploadCallback(fileId) {
    $("#Image").attr('src', getfile(fileId, '1'));
}
